import { createRouter, createWebHistory } from 'vue-router'
import CartList from '@/views/CartList/index.vue'
// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      //name: 'home',
      component: () => import('@/views/layout/index.vue'),
      children:[
        {
          path: '',
          component: () => import('@/views/home/index.vue'),
        },
        {
          path: 'category/:id',
          component: () => import('@/views/category/index.vue'),
        },
        {
          path: 'category/sub/:id',
          component: () => import('@/views/subCategory/index.vue'),
        },
        {
          path: 'detail/:id',
          component: () => import('@/views/Detail/index.vue'),
        },
        {
          path: '/cartlist',
          component: CartList
        },
        {
          path: '/checkout',
          component: () => import('@/views/Checkout/index.vue'),
        },
        {
          path: '/pay',
          component: () => import('@/views/pay/index.vue'),
        },
        {
          path: '/member',
          component: () => import('@/views/Member/index.vue'),
          children:[
            {
              path: 'order',
              component: () => import('@/views/Member/components/order.vue'),
            },
            {
              path: 'user',
              component: () => import('@/views/Member/components/user.vue'),
              
            },
            {
              path: '/paycallback',
              component: () => import('@/views/PayCallBack/index.vue'),
            }
          ],
          redirect: '/member/user',
        },
        {
          path: '/comment/:id',
          component: () => import('@/views/Comment/index.vue'),
        }
      ]
    },
    {
      path: '/login',
      //name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('@/views/login/index.vue'),
    },
  ],
  scrollBehavior() {
    return { top: 0 }
  },//定制路由滚动位置，top=0，就是重置滚动位置，即切换页面回到页面顶部
})

export default router
